var zclsh = Common.GetRequest().zclsh; //获取传入的update
var zydm = decodeURI(Common.GetRequest().zydm);//值域代码
var zdm = decodeURI(Common.GetRequest().zdm);//值代码
if (zclsh == "update") {
    queryZdm();
}
initOtherStyle();
//数据校验-服务名称
function validate() {
    var zdm = $.trim($("#zdm").val());
    if (zdm == '') {
        LayerWn.showAlert('值代码不能为空');
        return false;
    }
    var zmc = $.trim($("#zmc").val());
    if (zmc == '') {
        LayerWn.showAlert('值名称不能为空');
        return false;
    }
    return true;
}
/**
 * 保存/更新
 */
function save() {
    if(!validate())
        return false;
    var data = $("form").serializeJson();
    var url = "zygl/saveZyx";
    if (zclsh == "update") {
        url = "zygl/updateZyx";
        data.zdm = zdm;
    }else{
        data.zydm = zydm;
    }
    var formJSON = JSON.stringify(data);
    $.ajax({
        type: "POST",
        contentType: 'application/json',
        dataType: "json",
        url: url,
        data: formJSON,
        success: function (jsonData) {
            if (jsonData.code == 200) {   //保存成功
                LayerWn.showSucAlert('保存成功');
                for (var k = 0; k < parent.frames.length; k++) {
                    if (parent.frames[k].frameElement.src.indexOf("psms-zygl.html") != -1)
                        parent.frames[k].queryDataSource();
                }
                setTimeout(function () {
                    parent.layer.closeAll()
                }, 1000);
            } else if(jsonData.code == 201) {
                LayerWn.showAlert(jsonData.msg);
            }
        }
    });
}
//根据值代码获取数据
function queryZdm() {
    var queryParms={zdm:zdm,zydm:zydm};
    $.ajax({
        type: "GET",
        contentType: 'application/json',
        dataType: "json",
        url: "zygl/getZyx",
        data: queryParms,
        success: function (jsonData) {
            if (jsonData.code == 200) {
                $('#appForm').populateForm(jsonData.zyx);
                //值编码不可编辑
                $("#zdm").attr("disabled","disabled");
                initOtherStyle();
            } else {
            }
        }
    })
}
/**
 * 取消按钮
 */
function cancel() {
    parent.layer.closeAll();
}

/**
 * 界面其他样式加载
 */
function initOtherStyle() {
    $('.i-checks').iCheck({
        checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-green',
    });
}
